using System;
using System.Collections.Generic;
using System.Linq;
using I2.Loc;
using UnityEngine;

public class RaceGameMode : DefaultGameMode
{
	public override bool IsAutoStart()
	{
		return true;
	}

	public override void StartRound()
	{
		GameInfoWindow.instance.HideInterface();
	}

	public override void RestartRound()
	{
		RaceController.instance.Restart();
	}

	public override void EndRound()
	{
	}

	public override List<PlayersInfoScroll.PlayerInfoPanelParams> GetPlayersList<T>(Func<T, bool> filter)
	{
		List<PlayersInfoScroll.PlayerInfoPanelParams> list = new List<PlayersInfoScroll.PlayerInfoPanelParams>();
		List<RaceResult> list2 = new List<RaceResult>();
		bool flag = !RaceController.instance.gameIsEnded;
		list2 = ((!flag) ? RaceController.instance.raceResult : GameController.instance.listPlayers.Select((PlayerBehavior x) => new RaceResult
		{
			name = x.photonView.owner.GetValueByKey(PlayerPropsKeys.nickname, "Empty name in Props").ToUpper(),
			idPlayer = x.photonView.owner.GetValueByKey(PlayerPropsKeys.playerId, string.Empty).ToString(),
			time = 0f,
			mine = x.isMine
		}).ToList());
		if (filter != null)
		{
			list2 = list2.Where((RaceResult x) => filter(x as T)).ToList();
		}
		int num = 0;
		foreach (RaceResult item in list2)
		{
			Color magenta = Color.magenta;
			Color magenta2 = Color.magenta;
			if (item.mine)
			{
				magenta = GameInfoWindow.instance.myPlayerBG;
				magenta2 = GameInfoWindow.instance.myPlayerText;
				PVPManager.instance.myPlace = num + 1;
			}
			else
			{
				magenta = new Color(24f / 85f, 0.38039216f, 0.4117647f, 1f);
				magenta2 = Color.white;
			}
			string text;
			if (item.time > 0.1f)
			{
				TimeSpan timeSpan = TimeSpan.FromSeconds(item.time);
				text = ((timeSpan.Minutes <= 0) ? string.Format("{0:D2}.{1:D1}", timeSpan.Seconds, timeSpan.Milliseconds / 10) : string.Format("{0:D2}:{1:D2}.{2:D1}", timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds / 10));
			}
			else
			{
				text = "---";
			}
			list.Add(new PlayersInfoScroll.PlayerInfoPanelParams());
			list[num].place = num + 1;
			list[num].name = item.name;
			list[num].state1 = string.Empty;
			list[num].state2 = ((!flag) ? text : string.Empty);
			list[num].flagScore = 0;
			list[num].bgColor = magenta;
			list[num].textColor = magenta2;
			list[num].playerId = item.idPlayer;
			num++;
		}
		return list;
	}

	public override PlayersScrollType TypeOfScrollForGameMode()
	{
		return PlayersScrollType.Race;
	}

	public override string EndGameModeTitle()
	{
		return ScriptLocalization.Get("Game_Common/race_over");
	}
}
